<?php
if (isset($_POST['o']) &&  !empty($_POST['o']) ){
    include 'load.php';
    $openid=$_POST['o'];
    $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
    if (!$mysqli->set_charset("utf8")) {}
    
    $query=$mysqli->query("SELECT isold,phone,memberno FROM uinfo where openid='".$openid."' limit 0,1 ");
    $phone='';
    if($query->num_rows>0){
        $userInfo=$query->fetch_array();
        $phone= $userInfo['phone'];
        $MemberNo=$userInfo['memberno'];
        $isold=$userInfo['isold'];
        if(empty($MemberNo)){
            $url='https://member.elixir.com.cn/ugc/index.php/selim/get_memberno?mobile='.$phone;
            $data=json_decode(file_get_contents($url), true);
            if (empty($data['m'])){
                echo json_encode(array('msg'=>'reg')); //new
                $mysqli->close();
                exit;
            }else{
                $MemberNo=$data['m'];
                $url='https://member.elixir.com.cn/ugc/index.php/selim/get_membernoinfo?memberno='.$MemberNo;
                $memberData=json_decode(file_get_contents($url), true);

                $mysqli->query("update uinfo set isold='old',memberno='".$MemberNo."',username='".addslashes($memberData['name'])."',sheng='".$memberData['sheng']."',shi='".$memberData['shi']."'
,pcid='".$memberData['pcid']."',dizhi='".addslashes($memberData['dizhi'])."' where openid='".$openid."'  ");
            }
        }
        if ('new' == $isold){
            $msg='new';
        }else{
            $query=$mysqli->query("SELECT id FROM juan where openid='".$openid."' limit 0,1 ");
            if($query->num_rows>0){
                $msg='oldjump';
            }else{
                $msg='o';
                $mysqli->query("insert into juan(openid,createtime) values('".$openid."','".date("Y-m-d H:i:s")."') ");
            }
            
        }
        echo json_encode(array('msg'=>$msg,'m'=>$MemberNo));
        
    }else{
        echo json_encode(array('msg'=>'error')); //new
    }
    $mysqli->close();
 
    
}